package com.suntront.module_metertask.meterlist

import android.view.View
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleViewModel
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleviewActivity
import com.mtjsoft.www.kotlinmvputils.constants.RouterConstants
import com.suntront.lib_db.table.MeterT
import com.suntront.module_metertask.R
import com.suntront.module_metertask.adapter.MeterListAdapter

/**
 * 抄表任务的册本列表
 * @author mtj
 * @Package com.suntront.module_metertask.meterlist
 * @date 2020-05-27 15:03:38
 */
@Route(path = RouterConstants.MeterTask_MeterList)
class MeterListRecycleViewActivity : BaseRecycleviewActivity<MeterT, MeterListViewModel>() {

    /**
     * 注入路由传递的参数
     * type 0:抄表任务  1：抄表排序
     */
    @JvmField
    @Autowired
    var type = 0

    override fun providerVMClass(): Class<MeterListViewModel>? {
        return MeterListViewModel::class.java
    }

    override fun loadActivityInfo() {
        setPageTitle("册本列表")
        // 禁止上拉加载
        viewModel.load_more.value = false
    }

    override fun setItemDecoration(): Int {
        return 0
    }

    override fun setPageSize(): Int {
        // 每页大小，传最大值，此处不分页加载
        return Int.MAX_VALUE
    }

    override fun setLayoutManagerType(): BaseRecycleViewModel.LayoutManager {
        return BaseRecycleViewModel.LayoutManager.LinearLayoutManager
    }

    override fun setCount(): Int {
        return 2
    }

    override fun instanceAdapter(list: MutableList<MeterT>): BaseQuickAdapter<MeterT, BaseViewHolder> {
        return MeterListAdapter(getContext(), list, type, this)
    }

    override fun onItemClick(position: Int, view: View) {
        super.onItemClick(position, view)
        when (view.id) {
            R.id.datasyn_right_arrow1_icon -> { // 继续抄表
                ARouter.getInstance()
                    .build(RouterConstants.MeterTask_UserTDetail)
                    .withInt("rosterId", viewModel.list.value!![position].rosterId)
                    .navigation()
            }
            R.id.rl_task_item -> { // 抄表排序
                ARouter.getInstance()
                    .build(RouterConstants.MeterTask_UserTSort)
                    .withInt("rosterId", viewModel.list.value!![position].rosterId)
                    .navigation()
            }
        }
    }
}